package com.usc.blog.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.usc.blog.pojo.User;
import com.usc.blog.service.UserService;

/**
 *
 * @版权: Copyright (c) 2016-2017 *********公司技术开发部
 * @author : huangjiapeng
 * @E-mail:1625545295@qq.com
 * @版本: 1.0
 * @创建日期: 2019年4月15日 下午12:39:59
 * @ClassName UserReviseController
 * @类描述-Description: TODO
 * @修改记录:
 * @版本: 1.0
 */
@Controller
@RequestMapping("userRevise")
public class UserReviseController {

	@Autowired
	UserService userService;

	@RequestMapping("/updateInformationUI")
	public String toUpdateInformationUI(HttpSession session) {
		System.out.println("~~~~~~~~~~~~~~~~~~~");
		// 跳转修改界面
		return "user/update";
	}

	@RequestMapping("/toUpdateInformation")
	public String toUpdateInformation(HttpSession session, User user, HttpServletRequest request,
			HttpServletResponse response) {
		// 账号 昵称 姓名 密码
		User currentUser = (User) session.getAttribute("currentUser");
		// user 不为空就修改
		if (user.getNikename() != null) {
			currentUser.setNikename(user.getNikename());
		}
		if (user.getPassword() != null) {
			currentUser.setPassword(user.getPassword());
		}
		// int insert = userService.insert(currentUser);
		int updateByPrimaryKey = userService.updateByPrimaryKey(currentUser);
		if (updateByPrimaryKey == 1) {
			request.setAttribute("upadtemsg", "更新成功！");
		} else {
			request.setAttribute("upadtemsg", "更新失败！");
		}
		session.setAttribute("currentUser", user);
		return "user/update";
	}
}
